// pages/index/index.js
var util = require('../../utils/util.js');
Page({

	/**
	 * 页面的初始数据
	 */
	data: {
		"SolarTerms": [
			{
				"name": "处暑",
				"time": "2023-08-23",
				"pic": "https://636c-cloud1-3g39lqq2cbc35cd7-1318781271.tcb.qcloud.la/kit-cms-upload/2023-09-06/17581694007584397_处暑.jpg?sign=2af3a5ab6e271d5ee9e169d2d8158e7e&t=1694007927",
				"suitable":"多健脾利湿之品",
				"fir":"鹰乃祭鸟",
				"sea":"天地始肃",
				"thi":"禾乃登"
			},
			{
				"name": "白露",
				"time": "2023-09-08",
				"pic": "https://636c-cloud1-3g39lqq2cbc35cd7-1318781271.tcb.qcloud.la/kit-cms-upload/2023-09-06/13431694007565525_白露.jpg?sign=9371f8ab04575fdaf173997eaf794d46&t=1694008004",
				"suitable":"多润燥滋阴之品",
				"fir":"鸿雁来",
				"sea":"元鸟归",
				"thi":"群鸟养羞"
			},
			{
				"name": "秋分",
				"time": "2023-09-23",
				"pic": "https://636c-cloud1-3g39lqq2cbc35cd7-1318781271.tcb.qcloud.la/kit-cms-upload/2023-09-06/17321694007725164_秋分.jpg?sign=f2ac805632847dad820e2b0e9f145616&t=1694008023",
				"suitable":"多温性润燥之品",
				"fir":"雷始收声",
				"sea":"蛰虫坯户",
				"thi":"水始涸"
			},
			{
				"name": "寒霜",
				"time": "2023-10-08",
				"pic": "https://636c-cloud1-3g39lqq2cbc35cd7-1318781271.tcb.qcloud.la/kit-cms-upload/2023-09-06/11531694007650406_寒霜.jpg?sign=f0a4ed17ae07c0d0cc28e99fbf81be16&t=1694008056g",
				"suitable":"多甘淡多滋润",
				"fir":"鸿雁来宾",
				"sea":"雀入大水为蛤",
				"thi":"菊有黄华"
			},
			{
				"name": "霜降",
				"time": "2023-10-24",
				"pic": "https://636c-cloud1-3g39lqq2cbc35cd7-1318781271.tcb.qcloud.la/kit-cms-upload/2023-09-06/10011694007733618_霜降.jpg?sign=1b3756e0430820d0f0802c0c6e3c03eb&t=1694008070",
				"suitable":"少生冷多健脾",
				"fir":"豺乃祭兽",
				"sea":"草木黄落",
				"thi":"蛰虫咸俯"
			},
			{
				"name": "立冬",
				"time": "2023-11-08",
				"pic": "https://636c-cloud1-3g39lqq2cbc35cd7-1318781271.tcb.qcloud.la/kit-cms-upload/2023-09-06/16921694007679782_立冬.jpg?sign=f3c35b4ae6c46431d8178f9c2a2ab2bb&t=1694008082",
				"suitable":"多滋阴潜阳之品",
				"fir":"水始冰",
				"sea":"地始冻",
				"thi":"雉人大水为蜃"
			},
			{
				"name": "小雪",
				"time": "2023-11-22",
				"pic": "https://636c-cloud1-3g39lqq2cbc35cd7-1318781271.tcb.qcloud.la/kit-cms-upload/2023-09-06/16351694007773055_小雪.jpg?sign=f6c877edb6da253890ea14368419e4c7&t=1694008094",
				"suitable":"多温补益肾之品",
				"fir":"虹藏不见",
				"sea":"天气上升地气下降",
				"thi":"闭塞而成冬"
			},

			{
				"name": "大雪",
				"time": "2023-12-07",
				"pic": "https://636c-cloud1-3g39lqq2cbc35cd7-1318781271.tcb.qcloud.la/kit-cms-upload/2023-09-06/11831694007626778_大雪.jpg?sign=28661b67b6a7cf76d414768f43bd52ad&t=1695637699",
				"suitable":"多益气补血之品",
				"fir":"鹃鸥不呜",
				"sea":"虎始交",
				"thi":"荔挺出"
			},
			{
				"name": "冬至",
				"time": "2023-12-22",
				"pic": "https://636c-cloud1-3g39lqq2cbc35cd7-1318781271.tcb.qcloud.la/kit-cms-upload/2023-09-06/10461694007636381_冬至.jpg?sign=1357a3556a2b47daa232ff1249c0bad4&t=1695637734",
				"suitable":"多滋补之品",
				"fir":"蚯蚓结",
				"sea":"糜角解",
				"thi":"水泉动"
			},
			{
				"name": "小寒",
				"time": "2024-01-06",
				"pic": "https://636c-cloud1-3g39lqq2cbc35cd7-1318781271.tcb.qcloud.la/kit-cms-upload/2023-09-06/10451694007747532_小寒.jpg?sign=48c989c89828cdf815036bef7cd81764&t=1695637849",
				"suitable":"少黏硬少生冷",
				"fir":"雁北乡",
				"sea":"鹊始巢",
				"thi":"雉始鸲"
			},
			{
				"name": "大寒",
				"time": "2024-01-20",
				"pic": "https://636c-cloud1-3g39lqq2cbc35cd7-1318781271.tcb.qcloud.la/kit-cms-upload/2023-09-06/13821694007607560_大寒.jpg?sign=e3a38c98359c0373d8c4880593d049d8&t=1695637922",
				"suitable":"多温热少燥热 ",
				"fir":"鸡乳",
				"sea":"征鸟厉疾",
				"thi":"水泽腹坚"
			}
		]
	},


	/**
	 * 生命周期函数--监听页面加载
	 */
	onLoad(options) {



	},

	onLoad: function () {
		var timestamp = Date.parse(new Date(Date.parse(new Date())+ 60*60*1000*8).toISOString().substring(0,10));	
		// var timestamp = Date.parse("2023-09-08");
		var date = new Date(timestamp);
		//获取年  
		var Y = parseInt(date.getFullYear());
		//获取月  
		var M = parseInt((date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1));
		//获取当日 
		var D = parseInt(date.getDate() < 10 ? '0' + date.getDate() : date.getDate());
		var i;
		var dayNum, hou, yu;
		for (i = 0; i <= 24; i++) {
			var time1 = Date.parse(this.data.SolarTerms[i].time);
			if (timestamp < time1) 
			break;
		}
		i--;

		var time2 = Date.parse(this.data.SolarTerms[i].time);
		dayNum = Math.floor((timestamp - time2) / 86400000) + 1;
		hou = Math.floor(dayNum / 5) + 1;
		yu = dayNum % 5;
		if(yu == 0) yu = 5, hou--;
		if(hou == 4 && yu == 1)
		{
			hou = 3;
			yu = 6;
		}
		if(hou == 1 && yu == 1) yu = this.data.SolarTerms[i].fir;
		else if(hou == 2 && yu == 1) yu = this.data.SolarTerms[i].sea;
		else if(hou == 3 && yu == 1) yu = this.data.SolarTerms[i].thi;
		else yu = '第' + yu + '天';
		if(hou == 1) hou = '一';
		else if(hou == 2) hou = '二';
		else hou = '三';
		// const dateCompare = (timestamp, time2) => {
		// 	let dayNum = 0
		// 	if (timestamp > time2) {
		// 		dayNum = Math.floor((timestamp - time2) / 86400)
		// 	} else {
		// 		dayNum = Math.floor((timestamp - time2) / 86400)
		// 	}
		// 	return dayNum
		// }


		var season = this.data.SolarTerms[i].name;
		var pic = this.data.SolarTerms[i].pic;
		var suitable = this.data.SolarTerms[i].suitable;
		this.setData({
			Y: Y,
			M: M,
			D: D,
			season: season,
			pic: pic,
			dayNum:dayNum,
			hou: hou,
			yu : yu,
			suitable:suitable,
			dayNum:dayNum
		})
		// wx.loadFontFace({
		// 	family: 'ziti',
		// 	source: 'url("https://636c-cloud1-3g39lqq2cbc35cd7-1318781271.tcb.qcloud.la/kit-cms-upload/2023-09-07/10661694077067017_FangZhengKaiTi-GBK-1.ttf?sign=210dfb007c2aa2bfff7d5aeb1fee2fe1&t=1694077081")',
		// 	success: console.log
		// })

	},

	/**
	 * 生命周期函数--监听页面初次渲染完成
	 */
	onReady() {

	},

	/**
	 * 生命周期函数--监听页面显示
	 */
	onShow() {

	},

	/**
	 * 生命周期函数--监听页面隐藏
	 */
	onHide() {

	},

	/**
	 * 生命周期函数--监听页面卸载
	 */
	onUnload() {

	},

	/**
	 * 页面相关事件处理函数--监听用户下拉动作
	 */
	onPullDownRefresh() {

	},

	/**
	 * 页面上拉触底事件的处理函数
	 */
	onReachBottom() {

	},

	/**
	 * 用户点击右上角分享
	 */
	onShareAppMessage() {

	}
})